import requests


# 定义类  --  接口对象层
class EmpManagerApi():
    # 定义方法  - 添加员工
    def add_emp(self, req_header, req_body):
        return requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header,json=req_body)

    # 定义方法 - 查询员工
    def query_emp(self, emp_id, req_headers):
        return requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_headers)

    # 定义方法 - 修改员工
    def modify_emp(self, emp_id, req_headers, req_body):
        return  requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_headers,
                     json=req_body)

    # 定义方法 - 删除员工
    def del_emp(self, emp_id, req_headers):
        return requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id, headers=req_headers)


# 自测
if __name__ == '__main__':
    # 创建实例
    emp = EmpManagerApi()
    # 调用添加员工
    req_header = {"Authorization": "b2cec8fb-b3ce-4443-91e3-1cdf9c8adc80"}
    req_body = {"username": "user87655430", "mobile": "18947884780", "workNumber": "9527890aa"}
    resp = emp.add_emp(req_header, req_body)
    print("添加员工：", resp.json())

    print("-"*100)

    emp_id = "1584097430708695040"
    req_header = {"Authorization": "b2cec8fb-b3ce-4443-91e3-1cdf9c8adc80"}
    resp = emp.query_emp(emp_id, req_header)
    print("查询员工：", resp.json())

    print("-"*100)
    emp_id = "1584097430708695040"
    req_header = {"Authorization": "b2cec8fb-b3ce-4443-91e3-1cdf9c8adc80"}
    req_body = {"username": "至宗宝99"}
    resp = emp.modify_emp(emp_id, req_header, req_body)
    print("修改员工：", resp.json())

    print("-"*100)
    emp_id = "1584097430708695040"
    req_header = {"Authorization": "b2cec8fb-b3ce-4443-91e3-1cdf9c8adc80"}
    resp = emp.del_emp(emp_id, req_header)
    print("删除员工：", resp.json())